package com.dddd.blog.blogcommon.pojo;


import com.dddd.blog.blogcommon.constant.ResultCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 喵星球的大橘
 * 统一响应对象
 */
@Data
@SuppressWarnings("all")
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 7890913930768134726L;
    private int code;
    private String message;
    private T data;

    /**
     * @return
     * @param data 数据实体
     */
    public Result setResult(ResultCode resultCode){
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMsg());
        return result;
    }

    /**
     * @param code 响应状态码
     * @param message 响应消息
     * @return
     */
    public Result setResult(ResultCode resultCode, T data){
       Result result = this.setResult(resultCode);
       result.setData(data);
       return result;
    }

}
